<template>
  <div class="col main-content">
    <div class="row tool-bar">
      <div class="col">
        <div class="inline-item">
          <div class="label inline">
            买家:
          </div>
          <div class="inline">
            <h-user-choose v-model="search.applyId"></h-user-choose>
          </div>
        </div>

        <div class="inline-item">
          <div class="label inline">
            发货单号:
          </div>
          <div class="inline">
            <el-input v-model="search.sn" clearable></el-input>
          </div>
        </div>

        <div class="inline-item">
          <div class="label inline">
            订单日期:
          </div>
          <div class="inline">
            <h-date-range-picker v-model="search.date"/>
          </div>
        </div>
        <div class="inline-item">
          <el-button type="primary" @click="searchAction"><i class="fa fa-search"></i> 查询</el-button>
        </div>

        <div class="inline-item">
          <div class="label inline">
            排序:
          </div>
          <div class="inline">
            <el-radio-group v-model="orderName" @change="orderChange">
              <el-radio :label="2">按降序</el-radio>
              <el-radio :label="1">按升序</el-radio>
            </el-radio-group>
          </div>
        </div>

      </div>
    </div>
    <div class="row mt-15">
      <div class="col">
        <el-table
          :data="datas"
          border
          stripe
          tooltip-effect="dark"
          v-loading="loading"
        >
          <el-table-column
            type="selection"
            width="48" align="center">
          </el-table-column>
          <el-table-column type="expand" label="详情">
            <template slot-scope="props">
              <div class="expand-div">
                <el-table
                  :data="props.row.details"
                  tooltip-effect="dark"
                  border
                  stripe
                >
                  <el-table-column
                    label="订单编号"
                    width="120" prop="sn">
                  </el-table-column>
                  <el-table-column
                    label="商品信息"
                    min-width="280">
                    <template slot-scope="scope">
                      <h-good-info-display :admin="true" v-model="scope.row"></h-good-info-display>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="商品规格"
                    min-width="100"
                  >
                    <template slot-scope="scope">
                      <h-specs-display v-model="scope.row"></h-specs-display>
                    </template>
                  </el-table-column>

                  <el-table-column label="订单信息" min-width="200">
                    <template slot-scope="scope">
                      <h-order-info-display v-model="scope.row"></h-order-info-display>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="订单金额"
                    min-width="150">
                    <template slot-scope="scope">
                      <h-order-pay-info-display v-model="scope.row"/>
                    </template>
                  </el-table-column>
                  <el-table-column
                    label="状态信息" width="120" align="center">
                    <template slot-scope="scope">
                      <h-order-status-display v-model="scope.row" :apply="true" :dispatch="true" :arrival="true"
                                              :pay="true"/>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="sn"
            label="发货单号"
            width="120">
          </el-table-column>
          <el-table-column
            prop="nickName"
            label="买家信息"
            width="200">
            <template slot-scope="scope">
              <h-user-display v-model="scope.row.apply"></h-user-display>
            </template>
          </el-table-column>
          <el-table-column
            label="创建日期"
            width="160" prop="createTime">
          </el-table-column>
          <el-table-column
            label="联系信息"
            show-overflow-tooltip>
            <template slot-scope="scope">
              <div>联系人: {{scope.row.concat}}</div>
              <div>联系电话: {{scope.row.mobile}}</div>
              <div>联系地址: {{scope.row.district}} {{scope.row.address}}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="件数"
            width="50">
            <template slot-scope="scope">
              <span class="red">{{scope.row.num}}</span>
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="note">
          </el-table-column>


          <el-table-column
            label="操作" align="center" width="140" fixed="right">
            <template slot-scope="scope">
              <el-tooltip placement="top">
                <div slot="content">进行发货操作</div>
                <el-button type="text" @click="doExpress(scope.$index,scope.row)">
                  发货
                </el-button>
              </el-tooltip>

              <el-tooltip placement="top">
                <div slot="content">删除订单操作</div>
                <el-button type="text" @click="doDelete(scope.$index,scope.row)">
                  删除
                </el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
        <div class="h-pagination">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="search.pagination.page"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="search.pagination.size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="search.pagination.total">
          </el-pagination>
        </div>
      </div>
    </div>
    <h-express-dialog v-model="currentData" :show.sync="showExpressDialog" title="发货操作"
                      @success="expressSuccess"></h-express-dialog>
  </div>
</template>
<style>

</style>
<script>
  import HDateRangePicker from 'src/components/common/HDateRangePicker'
  import HUserChoose from 'src/components/common/HUserChoose'
  import AdminService from 'src/service/admin'
  import HUserDisplay from 'src/components/common/display/HUserDisplay'
  import HOrderStatusDisplay from 'src/components/common/display/HOrderStatusDisplay'
  import HSpecsDisplay from 'src/components/common/display/HSpecsDisplay'
  import TableMix from 'src/components/table-mix'
  import HExpressDialog from 'src/components/admin/common/HExpressDialog'
  import HGoodInfoDisplay from 'src/components/common/display/HGoodInfoDisplay'
  import HOrderInfoDisplay from 'src/components/common/display/HOrderInfoDisplay'
  import HOrderPayInfoDisplay from 'src/components/common/display/HOrderPayInfoDisplay'

  export default {
    name: 'HAdminDispatch',
    components: {
      HDateRangePicker,
      HExpressDialog, HOrderPayInfoDisplay,
      HUserChoose, HUserDisplay, HOrderStatusDisplay, HSpecsDisplay, HGoodInfoDisplay, HOrderInfoDisplay
    },
    mixins: [TableMix],
    data() {
      return {
        orderName: 1,
        datas: [],
        search: {
          dispatch: 0,
          sn: null,
          pagination: {
            total: 0,
            page: 1,
            limit: 10
          },
          needDetails: true,
          applyId: null,
          orderDate: [],
          orderBy: 'sn'
        },
        currentData: {},
        loading: false,
        showExpressDialog: false
      }
    },
    methods: {
      searchAction: function () {
        this.search.pagination.page = 1
        this.getDatas()
      },
      orderChange: function (v) {
        if (v == 1) {
          this.search.orderBy = "sn";
        } else {
          this.search.orderBy = "sn desc";
        }
        this.getDatas();
      },
      expressSuccess: function (data) {
        this.getDatas()
        this.showExpressDialog = false
      },
      doExpress: function (index, data) {
        this.currentData = data
        this.showExpressDialog = true
      },
      getDatas: function () {
        const me = this
        me.loading = true
        AdminService.searchDelivery(me.search).then(ds => {
          if (ds != null) {
            me.datas = ds.datas
            me.search.pagination = ds.pagination
          }
          me.loading = false
        })
      },
      handleSizeChange: function (size) {
        this.search.pagination.page = 1;
        this.search.pagination.limit = size;
        this.getDatas();
      },
      handleCurrentChange: function (page) {
        this.search.pagination.page = page;
        this.getDatas();
      },
      //删除订单
      doDelete: function (index, data) {
        const me = this;
        this.$confirm('此操作将永久删除该发货单, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          me.loading = true;
          AdminService.removeDelivery({
            ids: [data.id],
            status: 0
          }).then(ds => {
            if (ds != null) {
              me.$message.success("删除发货单【" + data.sn + "】成功。")
            }
            me.getDatas();
          })
        }).catch(() => {

        });
      }
    },
    mounted: function () {
      // this.initTalbeHeight(260)
      this.getDatas()
    }
  }
</script>
